<html>

	<head>
		<meta charset="UTF-8">
		<title>提交确认</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
		<style>
			.layui-form-checkbox[lay-skin=primary] {
				height: 30px !!important;
			}
			
			.layui-form-checkbox span {
				height: 30px;
			}
		</style>
	</head>

	<body style="min-width: 100% !important;max-width: 100% !important; width: 100% !important;">
		<div class="body">
			<!--提交确认操作-->
			<div class="layui-row" id="tijiaoDiv">
				<div class="layui-col-md10">
					<form class="layui-form mt20" id="tijiaoForm">
						<div class="layui-form-item">
							<label class="layui-form-label pl30">发布时间：</label>
							<div class="layui-input-block">
								<input type="text" id="date" name="data" class="layui-input w200" value="" disabled="disabled">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label pl30">站点：</label>
							<div class="layui-input-block">
								<input type='checkbox' lay-skin='primary' title="全选" lay-filter="checkboxAll" class="checkAll">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label pl30"></label>
							<div class="layui-input-block" id="check">
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button type="button" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="submitTijiao">提交</button>
							</div>
						</div>
					</form>
				</div>
			</div>
			<!--提交确认操作-->

		</div>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script src="../../js/common/data.js"></script>
		<script>
			var href = window.location.href;
			console.log("---" + href);
			var siteType = href.split("?")[1].split("=")[1].split("&")[0];
			console.log("siteType=" + siteType);
			var operationType = href.split("&")[1].split("=")[1];
			console.log("operationType=" + operationType);

			layui.use(['table', 'laydate', 'form'], function() {
				var form = layui.form,
					table = layui.table,
					laydate = layui.laydate;

				//请求站点接口
				$.ajax({
					url: baseUrl + "site/getListNoPage",
					type: "GET",
					async: false,
					success: function(data) {
						console.log(data);
						if(data.code == 200) {
							$("#check").empty(); //清空复选框
							var str = ''
							var dataNo = data.list;
							var datas = [];
							$.each(dataNo, function(i, item) {
								datas.push(item.siteName);
							});
							//								提取缓存站点
							console.log(siteType)
							if(siteType == 0) {
								var getcomfig = JSON.parse(window.sessionStorage.getItem("storeComfig"));
							} else if(siteType == 2) {
								var getcomfig = JSON.parse(window.sessionStorage.getItem("lngComfig"));
							} else if(siteType == 1) {
								var getcomfig = JSON.parse(window.sessionStorage.getItem("voltageComfig"));
							} else if(siteType == 3) {
								var getcomfig = JSON.parse(window.sessionStorage.getItem("plantComfig"));
							} else if(siteType == 4) {
								var getcomfig = JSON.parse(window.sessionStorage.getItem("directComfig"));
							};
							console.log(getcomfig);
							console.log(datas);
							if(operationType == 1) { //提交确认
//								url = "monitordata/submitConfirmData";
								for(var i = 0; i < datas.length; i++) {
								var items = datas[i];
								if(getcomfig[i]) {
									if(datas.indexOf(getcomfig[i].siteName) == -1) {
										console.log(getcomfig[i].siteName);
										str += "<input type='checkbox' name='siteName' class='checkChild' lay-filter='checkboxOne' lay-skin='primary' title='" + datas[i] + "'>";
									} else {

										if(getcomfig[i].status == 1) {
											console.log(2)
											str += "<input type='checkbox' name='siteName' disabled class='checkChild' lay-filter='checkboxOne' lay-skin='primary' title='" + datas[i] + "'>";
										} else {
											console.log(3)
											str += "<input type='checkbox' name='siteName' class='checkChild' lay-filter='checkboxOne' lay-skin='primary' title='" + datas[i] + "'>";
										}

									}
								} else {
									str += "<input type='checkbox' name='siteName' class='checkChild' lay-filter='checkboxOne' lay-skin='primary' title='" + datas[i] + "'>";
								}
							};
							} else if(operationType == 2) { //批准   已提交的数据、
								if(getcomfig.length == 0){
									str = '<p>暂无审批的数据</p>'
								}else{
									var num = 0;
									$.each(getcomfig,function(i,item){
										if(item.status == 1){
											num++;
											str += "<input type='checkbox' name='siteName' class='checkChild' lay-filter='checkboxOne' lay-skin='primary' title='" + datas[i] + "'>";
										};
									});
									if(num == 0){
										str = '<p>暂无审批的数据</p>'
									}
								}
								
							} else if(operationType == 3) { //取消批准
								if(getcomfig.length == 0){
									str = '<p>暂无审批的数据</p>'
								}else{
									var num = 0;
									$.each(getcomfig,function(i,item){
										if(item.status == 1){
											num++;
											str += "<input type='checkbox' name='siteName' class='checkChild' lay-filter='checkboxOne' lay-skin='primary' title='" + datas[i] + "'>";
										};
									});
									if(num == 0){
										str = '<p>暂无审批的数据</p>'
									}
								}
							}
							$("#check").append(str);
							//初始化发布时间
							var today = new Date();
							var submitTime = today.getFullYear() + '年' + (today.getMonth() + 1) + '月' + today.getDate() + '日'; 
							$("#date").attr('value', submitTime);
						} else {
							layer.msg("站点加载失败", {
								icon: 5
							});
						}
						form.render()
					}
				});

				//全选
				form.on('checkbox(checkboxAll)', function(data) {
					var a = data.elem.checked;
					console.log(data.elem)
//					$(".checkChild").prop("checked", true);
					console.log($(".checkChild"))
					if(a == true) {
						$.each($(".checkChild"), function(i,item) {
							if($(item).attr("disabled")){
								$(item).prop("checked", false);
							}else{
								$(item).prop("checked", true);
							}
						});
					} else {
						$(".checkChild").prop("checked", false);
					}
					form.render('checkbox');
				});

				//有一个未选中全选取消选中
				form.on('checkbox(checkboxOne)', function(data) {
					console.log(data);
					var item = $(".checkChild");
					for(var i = 0; i < item.length; i++) {
						console.log(item[i].checked);
						if(item[i].checked == false) {
							$(".checkAll").prop("checked", false);
							form.render('checkbox');
						}
					}
				});

				//提交
				form.on('submit(submitTijiao)', function(data) {
					//获取当前选中的checkbox的值
					var checkboxdatas = $('input[name=siteName]:checked');
					var siteNames = "";
					$.each(checkboxdatas, function() {
						siteNames += $(this).attr('title') + ",";
					});
					siteNames = siteNames.substring(0, siteNames.length - 1);
					console.log(siteNames);

					var url = "";
					if(operationType == 1) { //提交确认
						url = "monitordata/submitConfirmData";
					} else if(operationType == 2) { //批准
						url = "monitordata/approveData";
					} else if(operationType == 3) { //取消批准
						url = "monitordata/cancelApproveData";
					}

					if(siteNames != "" && siteNames != null) {
						ajaxPost({
							url: url,
							type: "POST",
							data: {
								siteType: siteType,
								siteNames: siteNames
							},
							dataType: "json",
							successFull: function(res) {
								console.log(res)
								layer.msg('提交成功', {
									icon: 6
								});
								setTimeout(function() {
									var mylay = parent.layer.getFrameIndex(window.name);
									parent.layer.close(mylay);
								}, 1000);
								//								if(siteType==0){//门店监控信息
								//									window.location.href = "./storeMoniterList.html";
								//								}else if(siteType==2){//LNG数据监控
								//									window.location.href = "./lngMoniterList.html";
								//								}else if(siteType==1){//调压站数据监控
								//									window.location.href = "./voltageMoniterList.html";
								//								}else if(siteType==3){//电厂数据监控
								//									window.location.href = "./plantMoniterList.html";
								//								}else if(siteType==4){//直属数据监控
								//									window.location.href = "./directMoniterList.html";
								//								}else if(siteType==6){//次高压气量平衡报表
								//									window.location.href = "./secondHignReportList.html";
								//								}else if(siteType==7){//高压气量平衡报表
								//									window.location.href = "./hignReportList.html";
								//								}else if(siteType==8){//LNG气量平衡报表
								//									window.location.href = "./lngReportList.html";
								//								}else if(siteType==9){//门站气量平衡报表
								//									window.location.href = "./stationReportList.html";
								//								}else if(siteType==10){//用户气量平衡报表
								//									window.location.href = "./userReportList.html";
								//								}else if(siteType==11){//门站每日提取量分析报表
								//									window.location.href = "./detailsReportList.html";
								//								}
							},
							errCallBack: function(res) {
								layer.msg(res.msg, {
									icon: 5
								});
							}
						})
					}
				});

			});
		</script>
	</body>

</html>